package com.jxm.thread.demo2.creat3;

import java.util.concurrent.FutureTask;

/**
 * @Author: jxm
 * @Description:
 * @Date: 2024-1-4 9:47
 * @Version: 1.0
 */
public class CallableTest {

    public static void main(String[] args) throws Exception{
        //创建Callable接口实现类的对象
        NumThread numThread = new NumThread();
        //创建FutureTask的对象
        FutureTask futureTask = new FutureTask<>(numThread);
        new Thread(futureTask).start();

        //6.获取Callable中call方法的返回值
        //get()返回值即为FutureTask构造器参数Callable实现类重写的call()的返回值。
        Object sum = futureTask.get();
        System.out.println("总和为：" + sum);

    }
}
